/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-27
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-15
 * @Description: 
 */

import 'package:chat_client/enums/chat_enum.dart' show ConversationType;
import 'package:chat_client/models/conversation_model.dart';
import 'package:chat_client/models/session_model.dart';
import 'package:chat_client/screens/chat/chat_page.dart';
import 'package:chat_client/services/socket/conversation_service.dart';
import 'package:chat_client/utils/route_tools.dart' show generatePath;
import 'package:flutter/material.dart';

// 路由
import 'package:chat_client/router/router.dart';
// 仓库
import 'package:chat_client/models/apply_model.dart';
import 'package:chat_client/models/user_model.dart';
import 'package:chat_client/models/conversation_model.dart';
// 服务
import 'package:chat_client/services/user_service.dart';
// 组件
import 'package:chat_client/widgets/c_loading.dart';
import 'package:chat_client/widgets/c_input_dialog.dart';
//工具
import 'package:chat_client/utils/current_limiting.dart';
import 'package:chat_client/utils/show_messae.dart';
// 枚举
import 'package:chat_client/screens/mobile/menu/aplly_list.dart';
import 'package:chat_client/screens/mobile/menu/send_allpy_page.dart';

import 'package:chat_client/models/conversation_model.dart';

class ConversationProvider extends ChangeNotifier {
  final ConversationService _conversationService = ConversationService.instance;

  List<Conversation> _conversationList = [];

  List<Conversation> get conversationList => _conversationList;

  ConversationProvider() {
    _conversationList = _conversationService.getLocalConversationList();
  }

  //

  navToWidget(Widget page) {
    RouteManager.navigateToWidget(page);
  }

  navBack() {
    RouteManager.goBack();
  }

  // 会话转跳
  navToChat(Conversation con) {
    int type = con.type;
    String id;
    if (type == ConversationType.user.value) {
      id = con.pivateId!;
    } else {
      id = con.groupId!;
    }
    final session = SessionModel(
      conversationId: con.conversationId,
      type: type,
      id: id,
      name: con.nickname,
    );
    RouteManager.navigateToWidget(ChatScreen(session: session));
  }

  ///
  refreshConversationList() {
    _conversationList = _conversationService.getLocalConversationList();
    notifyListeners();
  }
}
